package com.aaa.sls.service.impl;

import com.aaa.common.entity.Order;
import com.aaa.sls.service.OrderService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;
import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private RestTemplate restTemplate;

    @Override
    public Order selectOne(Integer id) {
        return restTemplate.getForObject("http://orderService/order/selectOne",Order.class);
    }

    @Override
    @HystrixCommand(fallbackMethod = "queryAllFallback")
    public List<Order> queryAll() {
        return restTemplate.getForObject("http://orderService/order/queryAll",List.class);
    }

//    查询所有订单的备份方法
    public List<Order> queryAllFallback(){
        List<Order> orders=new ArrayList<>();
        Order order=new Order();
        order.setId(4444);
        order.setMemberUsername("远程订单列表故障，请与管理员联系");
        orders.add(order);
        return orders;
    }
}
